package com.springapp.mvc.controller;

import com.ixakin.access.dao.EnterpriseDAO;
import com.ixakin.access.dao.types.Enterprise;
import com.springapp.mvc.form.login.LoginForm;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 *
 * @author ifullana
 */
@Controller
@RequestMapping("/")
public class LoginController {

   @RequestMapping (value ="", method = RequestMethod.GET)
   public String homeNone(ModelMap model){
      return home(model);
   }

   @RequestMapping (value ="login.do", method = RequestMethod.GET)
   public String home(ModelMap model){
      model.addAttribute("loginForm", new LoginForm());
      return "login";
   }

   
   @RequestMapping (value = "login.do", method = RequestMethod.POST)
   public String login(@ModelAttribute("loginForm") LoginForm loginForm, ModelMap model){
      EnterpriseDAO enterpriseDAO = new EnterpriseDAO();
      try {
         Enterprise enterprise = enterpriseDAO.findById(loginForm.getEnterpriseCode());
      } catch (Exception ex) {
         ex.printStackTrace();
      }
      if ("TEST".equals(loginForm.getEnterpriseCode())){
         return "main/index";
      }
      return "login";
   }
   
}
